package com.example.robertluozizhao.framecollectdemo.activity;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.FloatEvaluator;
import android.animation.IntEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.robertluozizhao.framecollectdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * test dev tag 22
 * test dev tag dev 22
 * Created by Lzz on 8/9/2019.
 */

public class ValueAnimationActivity extends AppCompatActivity {


    @BindView(R.id.iv_translation)
    ImageView mIvTranslation;
    @BindView(R.id.iv_scale)
    ImageView mIvScale;
    @BindView(R.id.iv_rotation)
    ImageView mIvRotation;
    @BindView(R.id.iv_alpha)
    ImageView mIvAlpha;
    @BindView(R.id.iv_animation_set)
    ImageView mIvAnimationSet;
    @BindView(R.id.iv_xml_animation_set)
    ImageView mIvXmlAnimationSet;
    @BindView(R.id.ll_backgroundColor)
    LinearLayout mLlBackgroundColor;
    @BindView(R.id.tv_orther_value_set)
    TextView mTvOrtherValueSet;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_value_animation);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {

        AccelerateInterpolator jl;
        LinearInterpolator sfl;

        FloatEvaluator sd;
        IntEvaluator slf;
        ArgbEvaluator s;
        Animator.AnimatorListener sf;
        ValueAnimator.AnimatorUpdateListener fsf;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @OnClick({R.id.btn_translation,
            R.id.btn_scale, R.id.btn_rotation, R.id.btn_alpha,
            R.id.btn_animation_set, R.id.btn_xml_animation_set,
            R.id.btn_backgroundColor,R.id.btn_orther_value_set})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_translation:
                //动画默认时间为300ms
                ValueAnimator objectAnimator = ObjectAnimator.ofFloat(mIvTranslation, "translationX",
                        0, 700, 0);
                objectAnimator.setDuration(5000);
                objectAnimator.start();
                break;
            case R.id.btn_scale:
                ObjectAnimator.ofFloat(mIvScale, "scaleX", 1f, 1.5f, 1f).start();
                break;
            case R.id.btn_rotation:
                ObjectAnimator.ofFloat(mIvRotation, "rotationX", 0, 360)
                        .setDuration(1000)
                        .start();
                break;
            case R.id.btn_alpha:
                ObjectAnimator.ofFloat(mIvAlpha, "alpha", 0.5f, 1f, 0.5f, 1f)
                        .setDuration(3000)
                        .start();
                break;
            case R.id.btn_backgroundColor:
                ValueAnimator colorAnimator = ObjectAnimator.ofInt(mLlBackgroundColor, "backgroundColor",
                        0xffff8080, 0xff8080ff);
                colorAnimator.setDuration(2000);
                colorAnimator.setEvaluator(new ArgbEvaluator());
                colorAnimator.setRepeatCount(ValueAnimator.INFINITE);
                colorAnimator.setRepeatMode(ValueAnimator.RESTART);
                colorAnimator.start();

                break;
            case R.id.btn_animation_set:

                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playTogether(
                        ObjectAnimator.ofFloat(mIvAnimationSet, "translationX",
                                0, 700, 0),
                        ObjectAnimator.ofFloat(mIvAnimationSet, "rotationX", 0, 360)
                        , ObjectAnimator.ofFloat(mIvAnimationSet, "rotationX", 0, 360)
                        , ObjectAnimator.ofFloat(mIvAnimationSet, "alpha", 0.5f, 1f, 0.5f, 1f)
                );
                animatorSet.setDuration(3000);
                animatorSet.start();
                break;

            case R.id.btn_xml_animation_set:
               /* AnimatorSet animatorSet1 = (AnimatorSet) AnimatorInflater.
                        loadAnimator(this, R.animator.value_anim_xml);
                animatorSet1.setTarget(mIvXmlAnimationSet);
                animatorSet1.start();*/

                Animator animator1 = AnimatorInflater.loadAnimator(this,R.animator.value_single_xml);
                animator1.setTarget(mIvXmlAnimationSet);
                animator1.start();


                break;
            case R.id.btn_orther_value_set:
                AnimatorSet animatorSet2 = new AnimatorSet();
                //平移动画循环播放
                ObjectAnimator animator = ObjectAnimator.ofFloat(mTvOrtherValueSet, "translationX",
                        0, 700, 0);
                animator.setRepeatCount(-1);
                animator.setRepeatMode(ObjectAnimator.RESTART);
                animatorSet2.playTogether(
                        animator,
                      /*  ObjectAnimator.ofInt(mTvOrtherValueSet, "background", //background需要xml可定义 但是没有公开设置方法不行
                                R.color.gray,R.color.red,R.color.gray),*/
                        ObjectAnimator.ofInt(mTvOrtherValueSet, "BackgroundColor",
                                R.color.green,R.color.red,R.color.gray,R.color.green),
                        ObjectAnimator.ofFloat(mTvOrtherValueSet, "textSize", 20, 30,20)
                        , ObjectAnimator.ofFloat(mTvOrtherValueSet, "rotationY", 0, 360)
                        , ObjectAnimator.ofFloat(mTvOrtherValueSet, "alpha", 0.5f, 1f, 0.5f, 1f)
                );
                animatorSet2.setDuration(3000);
                animatorSet2.start();
                break;
        }
    }
}
